package com.xiliu.server.modules.website.controller;

import com.xiliu.common.controller.BaseController;
import com.xiliu.common.enums.BusinessType;
import com.xiliu.common.result.R;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xiliu.common.annotation.Log;
import com.xiliu.server.modules.website.entity.XlSlide;
import com.xiliu.server.modules.website.service.IXlSlideService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xiliu.common.page.TableDataInfo;


/**
 * 幻灯片表Controller
 * 
 * @author xiliu
 * @date 2022-12-05
 */
@RestController
@RequestMapping("/website/slide")
public class XlSlideController extends BaseController {
    @Autowired
    private IXlSlideService xlSlideService;

    /**
     * 查询幻灯片表列表
     */
    @PreAuthorize("@customSs.hasPermi('website:slide:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlSlide xlSlide) {
        startPage();
        List<XlSlide> list = xlSlideService.selectXlSlideList(xlSlide);
        return getDataTable(list);
    }

    /**
     * 获取幻灯片表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('website:slide:query')")
    @GetMapping(value = "/{slideId}")
    public R getInfo(@PathVariable("slideId") Long slideId) {
        return R.ok(xlSlideService.selectXlSlideBySlideId(slideId));
    }

    /**
     * 新增幻灯片表
     */
    @PreAuthorize("@customSs.hasPermi('website:slide:create')")
    @Log(title = "幻灯片表", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody XlSlide xlSlide) {
        boolean success = xlSlideService.create(xlSlide);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改幻灯片表
     */
    @PreAuthorize("@customSs.hasPermi('website:slide:edit')")
    @Log(title = "幻灯片表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{slideId}")
    public R update(@PathVariable Long slideId,  @RequestBody XlSlide xlSlide) {
        xlSlide.setSlideId(slideId);
        boolean success = xlSlideService.update(xlSlide);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除幻灯片表
     */
    @PreAuthorize("@customSs.hasPermi('website:slide:remove')")
    @Log(title = "幻灯片表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{slideIds}")
    public R remove(@PathVariable Long[] slideIds) {
        return R.ok(xlSlideService.deleteXlSlideBySlideIds(slideIds));
    }
}
